package com.kocel.block.repository;

import com.kocel.block.model.TbBlockInventory;
import com.kocel.block.model.TbBlockRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TbBlockRecordRepository extends JpaRepository<TbBlockRecord,String> {
    @Query("from TbBlockRecord as m where m.state = '2' and (tbBlockInventory.blockNumber like %?1% or tbBlockInventory.product like %?1% or tbBlockInventory.meltingStove like %?1% or tbBlockInventory.castingNum like %?1% ) order by  tbBlockInventory.storageTime desc")
    List<TbBlockRecord> findForList(String blockNumber);

    @Query("from TbBlockRecord as m where m.state = '0' and (tbBlockInventory.blockNumber like %?1% or tbBlockInventory.product like %?1% or tbBlockInventory.meltingStove like %?1% or tbBlockInventory.castingNum like %?1% ) order by  tbBlockInventory.storageTime desc")
    List<TbBlockRecord> findForMatching(String blockNumber);

    @Query("from TbBlockRecord as m where m.state = '3' and (tbBlockInventory.blockNumber like %?1% or tbBlockInventory.product like %?1% or tbBlockInventory.meltingStove like %?1% or tbBlockInventory.castingNum like %?1% ) order by  tbBlockInventory.storageTime desc")
    List<TbBlockRecord> findForCheck(String blockNumber);

    @Query("from TbBlockRecord as m where m.state = '1' and (tbBlockInventory.blockNumber like %?1% or tbBlockInventory.product like %?1% or tbBlockInventory.meltingStove like %?1% or tbBlockInventory.castingNum like %?1% ) order by  tbBlockInventory.storageTime desc")
    List<TbBlockRecord> findForOut(String blockNumber);

    @Query("from TbBlockRecord as m where m.state = '4' and (tbBlockInventory.blockNumber like %?1% or tbBlockInventory.product like %?1% or tbBlockInventory.meltingStove like %?1% or tbBlockInventory.castingNum like %?1% ) order by  tbBlockInventory.storageTime desc")
    List<TbBlockRecord> findForOutReturn(String blockNumber);
}
